﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_CategoryManager : ASPXBaseClass
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["User"].ToString() != "admin")
        {
            Response.Redirect("~/Admin/RedirectLogin.htm");
        }
        if (!IsPostBack)
        {
            BindGdv();
        }
    }

    void BindGdv()
    {
        GZ.Entity.ECategory obj = new GZ.Entity.ECategory();
        this.rptCategoryList.DataSource = obj.GetCategory();
        this.rptCategoryList.DataBind();
    }

    protected void btnAdd_Click(object sender, EventArgs e)
    {        
        string CategroyName = this.txtCategoryName.Text;
        GZ.Entity.ECategory obj = new GZ.Entity.ECategory();
        obj.CategoryName = CategroyName;
        if (obj.Insert(obj))
        {
            this.txtCategoryName.Text = string.Empty;
            BindGdv();
        }
        else
        {//TODO 提醒
        }
    }


    /// <summary>
    /// 删除事件
    /// </summary>
    /// <param name="source"></param>
    /// <param name="e"></param>
    protected void rptCategoryList_ItemCommand(object source, RepeaterCommandEventArgs e)
    {

        int Id = Convert.ToInt16(e.CommandArgument);
        if (e.CommandName == "Del")
        {
            GZ.Entity.ECategory obj = new GZ.Entity.ECategory();
            if (obj.Del(Id))
            {
                BindGdv();
            }
            else
            {
                //TODO 提醒
            }
        }
    }
}